//
//  MCChooseForPlatformScreeningCell.swift
//  StoreManage
//
//  Created by MC on 2018/2/5.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

class MCChooseForPlatformScreeningCell: UICollectionViewCell {
    
    
    var model : MCChooseForPlatformScreeningModel = MCChooseForPlatformScreeningModel() {
        didSet {
            let str = model.nameCn + model.nameEn
            statusButton.setTitle(str, for: UIControlState.normal)
            
            statusButton.isSelected = model.isSelected
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(statusButton)
        statusButton.snp.remakeConstraints { (make) ->Void in
            make.edges.equalTo(self)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func statusButtonClicked() {
        statusButton.isSelected = !statusButton.isSelected
        model.isSelected = statusButton.isSelected
    }
    
    
    lazy var statusButton: UIButton = {
        let button = UIButton.init(type: UIButtonType.custom)
        button.titleLabel?.font = MCFont(14)
        button.layer.cornerRadius =  4
        button.layer.masksToBounds = true
        
        button.titleLabel?.lineBreakMode = NSLineBreakMode.byTruncatingTail
        
        button.setBackgroundImage(UIImage.init(color: UIColor.MCGray_light), for: UIControlState.normal)
        button.setTitleColor(UIColor.MCBlack, for: UIControlState.normal)
        
        button.setBackgroundImage(UIImage.init(color: UIColor.MCMain), for: UIControlState.selected)
        button.setTitleColor(UIColor.white, for: UIControlState.selected)
        
        button.addTarget(self, action: #selector(statusButtonClicked), for: UIControlEvents.touchUpInside)
        
        return button
    }()
    
    
}
